package linkedList

import "fmt"

type Node struct {
	Data      interface{}
	NextPoint *Node
	PrePoint  *Node
}

type LinkedList struct {
	head    *Node
	current *Node
	tail    *Node
}

func NewLinkedList(data []interface{}) *LinkedList {
	link := LinkedList{}
	var currentNode *Node
	for i := 0; i < len(data); i++ {
		currentNode = new(Node)
		currentNode.Data = data[i]
		link.InsertNode(currentNode)
	}
	return &link
}

func (link LinkedList) ShowLinkedList() {
	var currentNode *Node
	currentNode = link.head
	fmt.Println("Head Node:", link.head.Data)
	fmt.Println("Tail Node:", link.tail.Data)
	fmt.Println("Current Node:", link.current.Data)
	for {
		fmt.Println("Node:", currentNode.Data)
		if currentNode.NextPoint == nil {
			break
		} else {
			currentNode = currentNode.NextPoint
		}
	}
}

func (link *LinkedList) InsertNode(node *Node) {
	if link.head == nil {
		link.head = node
		link.tail = node
		link.current = node
	} else {
		link.tail.NextPoint = node
		node.PrePoint = link.tail
		link.tail = node
	}
}
